package com.foo.ui_demo_widge;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.PopupMenu;
import android.widget.Toast;

public class PopMenuDemoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pop_menu_demo);
        ImageButton ib = findViewById(R.id.ib_poopmenudemo);
        ib.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PopupMenu popupMenu = new PopupMenu(PopMenuDemoActivity.this, view);
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        int itemId = item.getItemId();
                        if (itemId==R.id.menu_edit||itemId==R.id.menu_mark||itemId==R.id.menu_delete){
                            Toast.makeText(PopMenuDemoActivity.this,item.getTitle(),Toast.LENGTH_SHORT).show();
                            return true;
                        }
                        return false;
                    }
                });
                popupMenu.getMenuInflater().inflate(R.menu.action_menu,popupMenu.getMenu());
                popupMenu.show();
            }
        });

    }
}